Goto statement in C Program

06-11-17 Course- C

The Goto statement is known as the Jump Statement in C language. It is used unconditionally for other labels. It transmits control in other parts of the program.

It is rarely used today because it makes program less readable and complex.

Syntax:


goto label;  

goto example

Let's see a simple example to use goto statement in C language.


#include <stdio.h>  
#include <conio.h>  
void main() {  
  int age;  
  clrscr();  
   ineligible:  
   printf("You are not eligible to vote!\n");  
  
   printf("Enter you age:\n");  
   scanf("%d", &age);  
   if(age<18)  
        goto ineligible;  
   else  
        printf("You are eligible to vote!\n");  
  
   getch();  
}  

Output:


You are not eligible to vote!
Enter you age:
11
You are not eligible to vote!
Enter you age:
44
You are eligible to vote!